<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册用户</title>
    <script type="application/javascript">
        //动态绑定，表单提交
        window.onload=function (){
            var register = document.getElementById("register");
        //绑定onsubmit事件
            register.onsubmit=function () {
                //获取username值
                var name = register.name.value;
                if(!(name.length >=4 && name.length <6)){
                    alert("长度(4-6)不满足");
                    return false;
                }
                var pwd = register.pwd.value;
                if(pwd.length!=6){
                    alert("长度(6)不满足");
                    return false;
                }
                var pwdI = register.pwdI.value;
                if(pwd!=pwdI){
                    alert("两次密码不一致");
                    return false;
                }
                var email = register.email.value;
                var emailPattern=/^[\w-]+@([a-zA-Z]+\.)+[a-zA-Z]+$/;
                if(!(emailPattern.test(email))){
                    alert("邮箱格式有误");
                    return false;
                }
                return true;
            }
        }
    </script>
</head>
<body >
<h1>注册用户</h1>
<form action="ok.html" id="register">
用户名:<input type="text" name="name">长度(4-6)<br>
密　码:<input type="password" name="pwd">长度(6)<br>
确　认:<input type="password" name="pwdI">长度(6)<br>
电　邮:<input type="text" name="email">满足基本格式<br>
<input type="submit"value="注册用户" >
</form>
</body>
</html>